﻿using System.Data;
using Core.Library;
using DataObject;

namespace Event.Controls.News
{
    public partial class Highlight : System.Web.UI.UserControl
    {
        #region variables, constants, properties
        private const int _imageWidth = 310;
        private const int _imageHeight = 200;
        private const string TITLE = @"<a title=""{1}"" href=""{2}"">{0}</a>";
        #endregion

        internal bool DataBind(DataTable dt)
        {
            if (dt != null && dt.Rows.Count > 0)
            {
                var r = dt.Rows[0];
                this.ltrImage.Text = Utils.Photo.BuildPhoto(
                    source: r[Constants.Table_News.News_ImageHomePage].ToString(),
                    title: r[Constants.Table_News.News_Title].ToString(),
                    href: r[Constants.Table_News.Url].ToString(),
                    width: _imageWidth,
                    height: _imageHeight,
                    mustThumb: true);
                this.ltrTitle.Text = string.Format(TITLE,r[Constants.Table_News.News_Title],
                    r[Constants.Table_News.EncodeTitle], r[Constants.Table_News.Url]);
                ltrPenName.Text = r[Constants.Table_News.News_PenName].ToString();
                ltrPublishDate.Text = r[Constants.Table_News.DisplayPublishDate].ToString();
                ltrSapo.Text = r[Constants.Table_News.News_Sapo].ToString();
                return true;
            }
            return false;
        }
    }
}